package com.caipiao.crawler.run;

import com.caipiao.constant.CrawlerConstants;
import com.caipiao.crawler.daletou.DaletouResultPage;
import com.caipiao.crawler.daletou.DaletouResultPipeline;
import us.codecraft.webmagic.Spider;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by adminitrator on 2018/7/28.
 */
public class Daletou implements RunCrawler {

    @Override
    public void run() {
        Spider.create(new DaletouResultPage())
                .addUrl(CrawlerConstants.DALETOU_HISTORY_URL)
                .addPipeline(new DaletouResultPipeline())
                .thread(4)
                .run();
    }

    @Override
    public void runHistory() {
        List<String> urls = new ArrayList<String>();
        for (int i = 18002; i < 18100; i++) {
            urls.add(CrawlerConstants.DALETOU_DATA_URL + i);
        }
//        urls.add(CrawlerConstants.DALETOU_DATA_URL + 18002);
        Spider.create(new DaletouResultPage())
                .addUrl(urls.toArray(new String[0]))
                .addPipeline(new DaletouResultPipeline())
                .thread(4)
                .run();
    }

    /**
     * 大乐透走势图
     */
    public void runCharts(){
        Spider.create(new DaletouResultPage())
                .addUrl(CrawlerConstants.DALETOU_CHART_URL)
                .addPipeline(new DaletouResultPipeline())
                .thread(4)
                .run();
    }
}
